part of '../page.dart';

class _PurchaseItemTile extends StatelessWidget with ScreenUtilMixin {
  const _PurchaseItemTile({
    required this.duration,
    required this.durationLabel,
    required this.priceWithCurrency,
    required this.priceLabel,
    required this.monthlyPriceLabel,
    required this.selected,
    required this.showPopularityBadge,
    required this.effectiveHeight,
    required this.effectiveFooterHeight,
    required this.onTap,
  });

  final String duration;
  final String durationLabel;
  final String priceWithCurrency;
  final String? priceLabel;
  final String? monthlyPriceLabel;
  final bool selected;
  final bool showPopularityBadge;
  final double effectiveHeight;
  final double effectiveFooterHeight;
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    const kPopularityBadgeHeight = 20.0;

    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        GestureDetector(
          onTap: onTap,
          child: Stack(
            children: [
              Padding(
                padding: const EdgeInsets.only(
                  top: kPopularityBadgeHeight / 2,
                ),
                child: Container(
                  height: effectiveHeight,
                  width: double.infinity,
                  decoration: BoxDecoration(
                    color: GoogleAppleStorePurchasePageTheme.of(context).purchaseItemTileColor,
                    border: Border.all(
                      color: selected
                          ? CoreTheme.of(context).primaryColor
                          : GoogleAppleStorePurchasePageTheme.of(context).purchaseItemTileColor,
                      width: 3,
                    ),
                    borderRadius: BorderRadius.circular(12),
                    boxShadow:
                        GoogleAppleStorePurchasePageTheme.of(context).purchaseItemTileShadows,
                  ),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        duration,
                        style: GoogleAppleStorePurchasePageTheme.of(context)
                            .textTheme
                            .purchaseItemTileDuration,
                      ),
                      Text(
                        durationLabel,
                        style: GoogleAppleStorePurchasePageTheme.of(context)
                            .textTheme
                            .purchaseItemTileDurationLabel,
                      ),
                      SizedBox(
                        height: 12 * logWidthScaleFactor,
                      ),
                      Text(
                        priceWithCurrency,
                        style: GoogleAppleStorePurchasePageTheme.of(context)
                            .textTheme
                            .purchaseItemTilePrice,
                      ),
                      SizedBox(
                        height: 14,
                        child: priceLabel == null
                            ? null
                            : Align(
                                alignment: Alignment.bottomCenter,
                                child: Text(
                                  priceLabel!,
                                  style: GoogleAppleStorePurchasePageTheme.of(context)
                                      .textTheme
                                      .purchaseItemTilePriceLabel,
                                  textAlign: TextAlign.center,
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                ),
                              ),
                      ),
                    ],
                  ),
                ),
              ),
              if (showPopularityBadge)
                Positioned.fill(
                  child: Align(
                    alignment: Alignment.topCenter,
                    child: Container(
                      height: kPopularityBadgeHeight,
                      decoration: BoxDecoration(
                          color: CoreTheme.of(context).primaryColor,
                          borderRadius: BorderRadius.circular(kPopularityBadgeHeight / 2)),
                      child: Padding(
                        padding: const EdgeInsets.symmetric(
                          horizontal: 8,
                        ),
                        child: Row(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Text(
                              GoogleAppleStorePurchasePageTranslation.of(context)
                                  .purchaseItemTileYearSubscriptionBadge,
                              style: GoogleAppleStorePurchasePageTheme.of(context)
                                  .textTheme
                                  .purchaseItemTileYearSubscriptionBadge,
                              textAlign: TextAlign.center,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              textWidthBasis: TextWidthBasis.longestLine,
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                ),
            ],
          ),
        ),
        SizedBox(
          height: effectiveFooterHeight,
          child: monthlyPriceLabel == null
              ? null
              : Align(
                  alignment: Alignment.bottomCenter,
                  child: Text(
                    monthlyPriceLabel!,
                    style: GoogleAppleStorePurchasePageTheme.of(context)
                        .textTheme
                        .purchaseItemTileMonthlyPrice,
                    textAlign: TextAlign.center,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
        ),
      ],
    );
  }
}
